﻿using System.Web.Routing;
using AutoMapper;
using mBlog.Models;
using mBlog.ViewModels;
using System.Web.Mvc;

namespace mBlog.Infrastructure.AutoMapper
{
    public class PostViewMappingProfile : AbstractProfile
    {
        protected override void Configure()
        {
            Mapper.CreateMap<Comment, CommentDetail>()
                .ForMember(detail => detail.Id,
                           o => o.MapFrom(c => c.ID))
                .ForMember(detail => detail.Content,
                           o => o.MapFrom(c => MvcHtmlString.Create(c.Content)))
                .ForMember(detail => detail.CreatedAt,
                           o => o.MapFrom(c => c.CommentTime.ToShortTimeString()));

            Mapper.CreateMap<Tag, TagDetail>()
                .ForMember(td => td.Name, o => o.MapFrom(t => t.Name))
                .ForMember(td => td.Url, o => o.MapFrom(t => UrlHelper.Action("View", "Tag", new {urlName = t.UrlName})));

            Mapper.CreateMap<Category, CategoryDetail>()
                .ForMember(cd => cd.Name, o => o.MapFrom(t => t.Name))
                .ForMember(cd => cd.Id, o => o.MapFrom(t => t.ID))
                .ForMember(cd => cd.Url,
                           o => o.MapFrom(t => UrlHelper.Action("View", "Category", new {urlName = t.UrlName})));

        }
    }
}